package com.tensquare.search.service;

import com.tensquare.search.dao.ArticleDao;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @BelongsProject: tensquare_parent
 * @BelongsPackage: com.tensquare.search.service
 * @Author: yang
 * @CreateTime: 2019-03-07 13:24
 * @Description: ${Description}
 */

@Service
@Transactional //可以不加 因为不是对数据库做操作
public class ArticleService {

    @Autowired
    private ArticleDao articleDao;
//    @Autowired
//    private IdWorker idWorker;

    public void save(Article ariticle){
     //   ariticle.setId(idWorker.nextId()+"");
        //不加id 他会自动生成 这里先使用自动生成的
        articleDao.save(ariticle);
    }

    public Page<Article> findByKey(String key, int page, int size) {
        Pageable pageable= PageRequest.of(page-1,size);
        return articleDao.findByTitleOrContentLike(key,key,pageable);
    }
}
